/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-12-10     xu       the first version
 */
#ifndef APPLICATIONS_HTTP_API_UTILS_H_
#define APPLICATIONS_HTTP_API_UTILS_H_

#include "cJSON.h"
#include <rtthread.h>

char* strdup_gbk(const char* str);

void copy_string_field(const char** target, cJSON* json, const char* name);

int add_string_field(cJSON* json, const char* name, const char* value);

int http_get(const char* uri, char** response, size_t* resp_len);

#define SAFE_FREE(field)       \
    if (field) {               \
        rt_free((void*)field); \
    }

#endif /* APPLICATIONS_HTTP_API_UTILS_H_ */